﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace _4_10
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 初始化候选名单
            listBox1.Items.Add("小王");
            listBox1.Items.Add("小李");
            listBox1.Items.Add("小陈");
            listBox1.Items.Add("小白");
            listBox1.Items.Add("小刘");
            listBox1.Items.Add("小徐");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 添加候选人
            if (textBox1.Text == "") return;
            listBox1.Items.Add(textBox1.Text);
            textBox1.Text = "";
            textBox1.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // 删除候选人
            if (listBox1.SelectedIndex == -1) return;
            listBox1.Items.RemoveAt(listBox1.SelectedIndex);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            // 去抽奖
            if (listBox1.Items.Count == 0)
            {
                MessageBox.Show("请先添加候选人！");
                return;
            }

            Form2 f2 = new Form2(listBox1);
            this.Hide();
            f2.ShowDialog();
            this.Show();
        }
    }
}
